<?php

namespace App\Console\Commands;

use App\Models\Setting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class EtPrice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'et_price';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每分钟定时更新ET兑换价格';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $redis = Redis::connection();
        $ticker = $redis->get('etf:ticker:ET/USDT');
        if ($ticker) {
            Setting::where('key', 'ytb_price')->update(['value' => bcadd(json_decode($ticker, true)['close'], 0, 4)]);
        }
    }
}
